home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / source / tsmorph30s.lha / TSM30s.lha / jpeg_ls / jpegdata.h < prev    next >
C/C++ Source or Header  |  1994-03-05  |  40KB  |  946 lines

  1. // Source code changed to allow GIF read etc to be used as JPEG read code
  2.  
  3. /*
  4.  * jpegdata.h
  5.  *
  6.  * Copyright (C) 1991, 1992, Thomas G. Lane.
  7.  * This file is part of the Independent JPEG Group's software.
  8.  * For conditions of distribution and use, see the accompanying README file.
  9.  *
  10.  * This file defines shared data structures for the various JPEG modules.
  11.  */
  12.  
  13.  
  14. /*
  15.  * You might need to change some of the following declarations if you are
  16.  * using the JPEG software within a surrounding application program
  17.  * or porting it to an unusual system.
  18.  */
  19.  
  20.  
  21. /* If the source or destination of image data is not to be stdio streams,
  22.  * these types may need work.  You can replace them with some kind of
  23.  * pointer or indicator that is useful to you, or just ignore 'em.
  24.  * Note that the user interface and the various jrdxxx/jwrxxx modules
  25.  * will also need work for non-stdio input/output.
  26.  */
  27.  
  28. #ifdef AMIGA_IO
  29. typedef BPTR JFILEREF;
  30. typedef BPTR IFILEREF;
  31. #else
  32. typedef FILE * JFILEREF;    /* source or dest of JPEG-compressed data */
  33.  
  34. typedef FILE * IFILEREF;    /* source or dest of non-JPEG image data */
  35. #endif
  36.  
  37. /* These defines are used in all function definitions and extern declarations.
  38.  * You could modify them if you need to change function linkage conventions,
  39.  * as is shown below for use with C++.  Another application would be to make
  40.  * all functions global for use with code profilers that require it.
  41.  * NOTE: the C++ test does the right thing if you are reading this include
  42.  * file in a C++ application to link to JPEG code that's been compiled with a
  43.  * regular C compiler.  I'm not sure it works if you try to compile the JPEG
  44.  * code with C++.
  45.  */
  46.  
  47. #define METHODDEF static    /* a function called through method pointers */
  48. #define LOCAL      static    /* a function used only in its module */
  49. #define GLOBAL            /* a function referenced thru EXTERNs */
  50. #ifdef __cplusplus
  51. #define EXTERN      extern "C"    /* a reference to a GLOBAL function */
  52. #else
  53. #define EXTERN      extern    /* a reference to a GLOBAL function */
  54. #endif
  55.  
  56.  
  57. /* Here is the pseudo-keyword for declaring pointers that must be "far"
  58.  * on 80x86 machines.  Most of the specialized coding for 80x86 is handled
  59.  * by just saying "FAR *" where such a pointer is needed.  In a few places
  60.  * explicit coding is needed; see uses of the NEED_FAR_POINTERS symbol.
  61.  */
  62.  
  63. #ifdef NEED_FAR_POINTERS
  64. #define FAR  far
  65. #else
  66. #define FAR
  67. #endif
  68.  
  69.  
  70.  
  71. /* The remaining declarations are not system-dependent, we hope. */
  72.  
  73.  
  74. /*
  75.  * NOTE: if you have an ancient, strict-K&R C compiler, it may choke on the
  76.  * similarly-named fields in Compress_info_struct and Decompress_info_struct.
  77.  * If this happens, you can get around it by rearranging the two structs so
  78.  * that the similarly-named fields appear first and in the same order in
  79.  * each struct.  Since such compilers are now pretty rare, we haven't done
  80.  * this in the portable code, preferring to maintain a logical ordering.
  81.  */
  82.  
  83.  
  84.  
  85. /* This macro is used to declare a "method", that is, a function pointer. */
  86. /* We want to supply prototype parameters if the compiler can cope. */
  87. /* Note that the arglist parameter must be parenthesized! */
  88.  
  89. #ifdef PROTO
  90. #define METHOD(type,methodname,arglist)  type (*methodname) arglist
  91. #else
  92. #define METHOD(type,methodname,arglist)  type (*methodname) ()
  93. #endif
  94.  
  95. /* Forward references to lists of method pointers */
  96. typedef struct External_methods_struct * external_methods_ptr;
  97. typedef struct Compress_methods_struct * compress_methods_ptr;
  98. typedef struct Decompress_methods_struct * decompress_methods_ptr;
  99.  
  100.  
  101. /* Data structures for images containing either samples or coefficients. */
  102. /* Note that the topmost (leftmost) index is always color component. */
  103. /* On 80x86 machines, the image arrays are too big for near pointers, */
  104. /* but the pointer arrays can fit in near memory. */
  105.  
  106. typedef JSAMPLE FAR *JSAMPROW;    /* ptr to one image row of pixel samples. */
  107. typedef JSAMPROW *JSAMPARRAY;    /* ptr to some rows (a 2-D sample array) */
  108. typedef JSAMPARRAY *JSAMPIMAGE;    /* a 3-D sample array: top index is color */
  109.  
  110.  
  111. #define DCTSIZE        8    /* The basic DCT block is 8x8 samples */
  112. #define DCTSIZE2    64    /* DCTSIZE squared; # of elements in a block */
  113.  
  114. typedef JCOEF JBLOCK[DCTSIZE2];    /* one block of coefficients */
  115. typedef JBLOCK FAR *JBLOCKROW;    /* pointer to one row of coefficient blocks */
  116. typedef JBLOCKROW *JBLOCKARRAY;        /* a 2-D array of coefficient blocks */
  117. typedef JBLOCKARRAY *JBLOCKIMAGE;    /* a 3-D array of coefficient blocks */
  118.  
  119. typedef JCOEF FAR *JCOEFPTR;    /* useful in a couple of places */
  120.  
  121.  
  122. /* The input and output data of the DCT transform subroutines are of
  123.  * the following type, which need not be the same as JCOEF.
  124.  * For example, on a machine with fast floating point, it might make sense
  125.  * to recode the DCT routines to use floating point; then DCTELEM would be
  126.  * 'float' or 'double'.
  127.  */
  128.  
  129. typedef JCOEF DCTELEM;
  130. typedef DCTELEM DCTBLOCK[DCTSIZE2];
  131.  
  132.  
  133. /* Types for JPEG compression parameters and working tables. */
  134.  
  135.  
  136. typedef enum {            /* defines known color spaces */
  137.     CS_UNKNOWN,        /* error/unspecified */
  138.     CS_GRAYSCALE,        /* monochrome (only 1 component) */
  139.     CS_RGB,            /* red/green/blue */
  140.     CS_YCbCr,        /* Y/Cb/Cr (also known as YUV) */
  141.     CS_YIQ,            /* Y/I/Q */
  142.     CS_CMYK            /* C/M/Y/K */
  143. } COLOR_SPACE;
  144.  
  145.  
  146. typedef struct {        /* Basic info about one component */
  147.   /* These values are fixed over the whole image */
  148.   /* For compression, they must be supplied by the user interface; */
  149.   /* for decompression, they are read from the SOF marker. */
  150.     short component_id;    /* identifier for this component (0..255) */
  151.     short component_index;    /* its index in SOF or cinfo->comp_info[] */
  152.     short h_samp_factor;    /* horizontal sampling factor (1..4) */
  153.     short v_samp_factor;    /* vertical sampling factor (1..4) */
  154.     short quant_tbl_no;    /* quantization table selector (0..3) */
  155.   /* These values may vary between scans */
  156.   /* For compression, they must be supplied by the user interface; */
  157.   /* for decompression, they are read from the SOS marker. */
  158.     short dc_tbl_no;    /* DC entropy table selector (0..3) */
  159.     short ac_tbl_no;    /* AC entropy table selector (0..3) */
  160.   /* These values are computed during compression or decompression startup */
  161.     long true_comp_width;    /* component's image width in samples */
  162.     long true_comp_height;    /* component's image height in samples */
  163.     /* the above are the logical dimensions of the downsampled image */
  164.   /* These values are computed before starting a scan of the component */
  165.     short MCU_width;    /* number of blocks per MCU, horizontally */
  166.     short MCU_height;    /* number of blocks per MCU, vertically */
  167.     short MCU_blocks;    /* MCU_width * MCU_height */
  168.     long downsampled_width;    /* image width in samples, after expansion */
  169.     long downsampled_height; /* image height in samples, after expansion */
  170.     /* the above are the true_comp_xxx values rounded up to multiples of */
  171.     /* the MCU dimensions; these are the working dimensions of the array */
  172.     /* as it is passed through the DCT or IDCT step.  NOTE: these values */
  173.     /* differ depending on whether the component is interleaved or not!! */
  174. } jpeg_component_info;
  175.  
  176.  
  177. /* DCT coefficient quantization tables.
  178.  * For 8-bit precision, 'INT16' should be good enough for quantization values;
  179.  * for more precision, we go for the full 16 bits.  'INT16' provides a useful
  180.  * speedup on many machines (multiplication & division of JCOEFs by
  181.  * quantization values is a significant chunk of the runtime).
  182.  * Note: the values in a QUANT_TBL are always given in zigzag order.
  183.  */
  184. #ifdef EIGHT_BIT_SAMPLES
  185. typedef INT16 QUANT_VAL;    /* element of a quantization table */
  186. #else
  187. typedef UINT16 QUANT_VAL;    /* element of a quantization table */
  188. #endif
  189. typedef QUANT_VAL QUANT_TBL[DCTSIZE2];    /* A quantization table */
  190. typedef QUANT_VAL * QUANT_TBL_PTR;    /* pointer to same */
  191.  
  192.  
  193. typedef struct {        /* A Huffman coding table */
  194.   /* These two fields directly represent the contents of a JPEG DHT marker */
  195.     UINT8 bits[17];        /* bits[k] = # of symbols with codes of */
  196.                 /* length k bits; bits[0] is unused */
  197.     UINT8 huffval[256];    /* The symbols, in order of incr code length */
  198.   /* This field is used only during compression.  It's initialized FALSE when
  199.    * the table is created, and set TRUE when it's been output to the file.
  200.    */
  201.     boolean sent_table;    /* TRUE when table has been output */
  202.   /* The remaining fields are computed from the above to allow more efficient
  203.    * coding and decoding.  These fields should be considered private to the
  204.    * Huffman compression & decompression modules.
  205.    */
  206.     /* encoding tables: */
  207.     UINT16 ehufco[256];    /* code for each symbol */
  208.     char ehufsi[256];    /* length of code for each symbol */
  209.     /* decoding tables: (element [0] of each array is unused) */
  210.     UINT16 mincode[17];    /* smallest code of length k */
  211.     INT32 maxcode[18];    /* largest code of length k (-1 if none) */
  212.     /* (maxcode[17] is a sentinel to ensure huff_DECODE terminates) */
  213.     short valptr[17];    /* huffval[] index of 1st symbol of length k */
  214. } HUFF_TBL;
  215.  
  216.  
  217. #define NUM_QUANT_TBLS      4    /* quantization tables are numbered 0..3 */
  218. #define NUM_HUFF_TBLS       4    /* Huffman tables are numbered 0..3 */
  219. #define NUM_ARITH_TBLS      16    /* arith-coding tables are numbered 0..15 */
  220. #define MAX_COMPS_IN_SCAN   4    /* JPEG limit on # of components in one scan */
  221. #define MAX_SAMP_FACTOR     4    /* JPEG limit on sampling factors */
  222. #define MAX_BLOCKS_IN_MCU   10    /* JPEG limit on # of blocks in an MCU */
  223.  
  224. /* Working data for compression */
  225.  
  226. struct Compress_info_struct {
  227. /*
  228.  * All of these fields shall be established by the user interface before
  229.  * calling jpeg_compress, or by the input_init or c_ui_method_selection
  230.  * methods.
  231.  * Most parameters can be set to reasonable defaults by j_c_defaults.
  232.  * Note that the UI must supply the storage for the main methods struct,
  233.  * though it sets only a few of the methods there.
  234.  */
  235.     compress_methods_ptr methods; /* Points to list of methods to use */
  236.  
  237.     external_methods_ptr emethods; /* Points to list of methods to use */
  238.  
  239.     IFILEREF input_file;    /* tells input routines where to read image */
  240.     JFILEREF output_file;    /* tells output routines where to write JPEG */
  241.  
  242.     long image_width;    /* input image width */
  243.     long image_height;    /* input image height */
  244.     short input_components;    /* # of color components in input image */
  245.  
  246.     short data_precision;    /* bits of precision in image data */
  247.  
  248.     COLOR_SPACE in_color_space; /* colorspace of input file */
  249.     COLOR_SPACE jpeg_color_space; /* colorspace of JPEG file */
  250.  
  251. //    double input_gamma;    /* image gamma of input file */
  252.  
  253.     boolean write_JFIF_header; /* should a JFIF marker be written? */
  254.     /* These three values are not used by the JPEG code, only copied */
  255.     /* into the JFIF APP0 marker.  density_unit can be 0 for unknown, */
  256.     /* 1 for dots/inch, or 2 for dots/cm.  Note that the pixel aspect */
  257.     /* ratio is defined by X_density/Y_density even when density_unit=0. */
  258.     UINT8 density_unit;    /* JFIF code for pixel size units */
  259.     UINT16 X_density;    /* Horizontal pixel density */
  260.     UINT16 Y_density;    /* Vertical pixel density */
  261.  
  262.     short num_components;    /* # of color components in JPEG image */
  263.     jpeg_component_info * comp_info;
  264.     /* comp_info[i] describes component that appears i'th in SOF */
  265.  
  266.     QUANT_TBL_PTR quant_tbl_ptrs[NUM_QUANT_TBLS];
  267.     /* ptrs to coefficient quantization tables, or NULL if not defined */
  268.  
  269.     HUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  270.     HUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  271.     /* ptrs to Huffman coding tables, or NULL if not defined */
  272.  
  273.     UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arithmetic-coding tables */
  274.     UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arithmetic-coding tables */
  275.     UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arithmetic-coding tables */
  276.  
  277.     boolean arith_code;    /* TRUE=arithmetic coding, FALSE=Huffman */
  278.     boolean interleave;    /* TRUE=interleaved output, FALSE=not */
  279.     boolean optimize_coding; /* TRUE=optimize entropy encoding parms */
  280.     boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  281.     int smoothing_factor;    /* 1..100, or 0 for no input smoothing */
  282.  
  283.     /* The restart interval can be specified in absolute MCUs by setting
  284.      * restart_interval, or in MCU rows by setting restart_in_rows
  285.      * (in which case the correct restart_interval will be figured
  286.      * for each scan).
  287.      */
  288.     UINT16 restart_interval;/* MCUs per restart interval, or 0 for no restart */
  289.     int restart_in_rows;    /* if > 0, MCU rows per restart interval */
  290.  
  291. /*
  292.  * These fields are computed during jpeg_compress startup
  293.  */
  294.     short max_h_samp_factor; /* largest h_samp_factor */
  295.     short max_v_samp_factor; /* largest v_samp_factor */
  296.  
  297. /*
  298.  * These fields may be useful for progress monitoring
  299.  */
  300.  
  301.     int total_passes;    /* number of passes expected */
  302.     int completed_passes;    /* number of passes completed so far */
  303.  
  304. /*
  305.  * These fields are valid during any one scan
  306.  */
  307.     short comps_in_scan;    /* # of JPEG components output this time */
  308.     jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  309.     /* *cur_comp_info[i] describes component that appears i'th in SOS */
  310.  
  311.     long MCUs_per_row;    /* # of MCUs across the image */
  312.     long MCU_rows_in_scan;    /* # of MCU rows in the image */
  313.  
  314.     short blocks_in_MCU;    /* # of DCT blocks per MCU */
  315.     short MCU_membership[MAX_BLOCKS_IN_MCU];
  316.     /* MCU_membership[i] is index in cur_comp_info of component owning */
  317.     /* i'th block in an MCU */
  318.  
  319.     /* these fields are private data for the entropy encoder */
  320.     JCOEF last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each comp */
  321.     JCOEF last_dc_diff[MAX_COMPS_IN_SCAN]; /* last DC diff for each comp */
  322.     UINT16 restarts_to_go;    /* MCUs left in this restart interval */
  323.     short next_restart_num;    /* # of next RSTn marker (0..7) */
  324. };
  325.  
  326. typedef struct Compress_info_struct * compress_info_ptr;
  327.  
  328.  
  329. /* Working data for decompression */
  330.  
  331. struct Decompress_info_struct {
  332. /*
  333.  * These fields shall be established by the user interface before
  334.  * calling jpeg_decompress.
  335.  * Most parameters can be set to reasonable defaults by j_d_defaults.
  336.  * Note that the UI must supply the storage for the main methods struct,
  337.  * though it sets only a few of the methods there.
  338.  */
  339.     decompress_methods_ptr methods; /* Points to list of methods to use */
  340.  
  341.     external_methods_ptr emethods; /* Points to list of methods to use */
  342.  
  343.     JFILEREF input_file;    /* tells input routines where to read JPEG */
  344.     IFILEREF output_file;    /* tells output routines where to write image */
  345.  
  346.     /* these can be set at d_ui_method_selection time: */
  347.  
  348.     COLOR_SPACE out_color_space; /* colorspace of output */
  349.  
  350. //    double output_gamma;    /* image gamma wanted in output */
  351.  
  352.     boolean quantize_colors; /* T if output is a colormapped format */
  353.     /* the following are ignored if not quantize_colors: */
  354.     boolean two_pass_quantize;    /* use two-pass color quantization? */
  355.     boolean use_dithering;        /* want color dithering? */
  356.     int desired_number_of_colors;    /* max number of colors to use */
  357.  
  358.     boolean do_block_smoothing; /* T = apply cross-block smoothing */
  359.     boolean do_pixel_smoothing; /* T = apply post-upsampling smoothing */
  360.  
  361. /*
  362.  * These fields are used for efficient buffering of data between read_jpeg_data
  363.  * and the entropy decoding object.  By using a shared buffer, we avoid copying
  364.  * data and eliminate the need for an "unget" operation at the end of a scan.
  365.  * The actual source of the data is known only to read_jpeg_data; see the
  366.  * JGETC macro, below.
  367.  * Note: the user interface is expected to allocate the input_buffer and
  368.  * initialize bytes_in_buffer to 0.  Also, for JFIF/raw-JPEG input, the UI
  369.  * actually supplies the read_jpeg_data method.  This is all handled by
  370.  * j_d_defaults in a typical implementation.
  371.  */
  372.     char * input_buffer;    /* start of buffer (private to input code) */
  373.     char * next_input_byte;    /* => next byte to read from buffer */
  374.     int bytes_in_buffer;    /* # of bytes remaining in buffer */
  375.  
  376. /*
  377.  * These fields are set by read_file_header or read_scan_header
  378.  */
  379.     long image_width;    /* overall image width */
  380.     long image_height;    /* overall image height */
  381.  
  382.     short data_precision;    /* bits of precision in image data */
  383.  
  384.     COLOR_SPACE jpeg_color_space; /* colorspace of JPEG file */
  385.  
  386.         /* These three values are not used by the JPEG code, merely copied */
  387.     /* from the JFIF APP0 marker (if any). */
  388.     UINT8 density_unit;    /* JFIF code for pixel size units */
  389.     UINT16 X_density;    /* Horizontal pixel density */
  390.     UINT16 Y_density;    /* Vertical pixel density */
  391.  
  392.     short num_components;    /* # of color components in JPEG image */
  393.     jpeg_component_info * comp_info;
  394.     /* comp_info[i] describes component that appears i'th in SOF */
  395.  
  396.     QUANT_TBL_PTR quant_tbl_ptrs[NUM_QUANT_TBLS];
  397.     /* ptrs to coefficient quantization tables, or NULL if not defined */
  398.  
  399.     HUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  400.     HUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  401.     /* ptrs to Huffman coding tables, or NULL if not defined */
  402.  
  403.     UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  404.     UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  405.     UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  406.  
  407.     boolean arith_code;    /* TRUE=arithmetic coding, FALSE=Huffman */
  408.     boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  409.  
  410.     UINT16 restart_interval;/* MCUs per restart interval, or 0 for no restart */
  411.  
  412. /*
  413.  * These fields are computed during jpeg_decompress startup
  414.  */
  415.     short max_h_samp_factor; /* largest h_samp_factor */
  416.     short max_v_samp_factor; /* largest v_samp_factor */
  417.  
  418.     short color_out_comps;    /* # of color components output by color_convert */
  419.                 /* (need not match num_components) */
  420.     short final_out_comps;    /* # of color components sent to put_pixel_rows */
  421.     /* (1 when quantizing colors, else same as color_out_comps) */
  422.  
  423.     JSAMPLE * sample_range_limit; /* table for fast range-limiting */
  424.  
  425. /*
  426.  * When quantizing colors, the color quantizer leaves a pointer to the output
  427.  * colormap in these fields.  The colormap is valid from the time put_color_map
  428.  * is called (must be before any put_pixel_rows calls) until shutdown (more
  429.  * specifically, until free_all is called to release memory).
  430.  */
  431.     int actual_number_of_colors; /* actual number of entries */
  432.     JSAMPARRAY colormap;    /* NULL if not valid */
  433.     /* map has color_out_comps rows * actual_number_of_colors columns */
  434.  
  435. /*
  436.  * These fields may be useful for progress monitoring
  437.  */
  438.  
  439.     int total_passes;    /* number of passes expected */
  440.     int completed_passes;    /* number of passes completed so far */
  441.  
  442. /*
  443.  * These fields are valid during any one scan
  444.  */
  445.     short comps_in_scan;    /* # of JPEG components input this time */
  446.     jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  447.     /* *cur_comp_info[i] describes component that appears i'th in SOS */
  448.  
  449.     long MCUs_per_row;    /* # of MCUs across the image */
  450.     long MCU_rows_in_scan;    /* # of MCU rows in the image */
  451.  
  452.     short blocks_in_MCU;    /* # of DCT blocks per MCU */
  453.     short MCU_membership[MAX_BLOCKS_IN_MCU];
  454.     /* MCU_membership[i] is index in cur_comp_info of component owning */
  455.     /* i'th block in an MCU */
  456.  
  457.     /* these fields are private data for the entropy encoder */
  458.     JCOEF last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each comp */
  459.     JCOEF last_dc_diff[MAX_COMPS_IN_SCAN]; /* last DC diff for each comp */
  460.     UINT16 restarts_to_go;    /* MCUs left in this restart interval */
  461.     short next_restart_num;    /* # of next RSTn marker (0..7) */
  462.  
  463.     short input_components;    /* # of color components in input image */
  464.     COLOR_SPACE in_color_space; /* colorspace of input file */
  465. };
  466.  
  467. typedef struct Decompress_info_struct * decompress_info_ptr;
  468.  
  469. /* Macros for reading data from the decompression input buffer */
  470.  
  471. #ifdef CHAR_IS_UNSIGNED
  472. #define JGETC(cinfo)    ( --(cinfo)->bytes_in_buffer < 0 ? \
  473.              (*(cinfo)->methods->read_jpeg_data) (cinfo) : \
  474.              (int) (*(cinfo)->next_input_byte++) )
  475. #else
  476. #define JGETC(cinfo)    ( --(cinfo)->bytes_in_buffer < 0 ? \
  477.              (*(cinfo)->methods->read_jpeg_data) (cinfo) : \
  478.              (int) (*(cinfo)->next_input_byte++) & 0xFF )
  479. #endif
  480.  
  481. #define JUNGETC(ch,cinfo)  ((cinfo)->bytes_in_buffer++, \
  482.                 *(--((cinfo)->next_input_byte)) = (char) (ch))
  483.  
  484. #define MIN_UNGET    4    /* may always do at least 4 JUNGETCs */
  485.  
  486.  
  487. /* A virtual image has a control block whose contents are private to the
  488.  * memory manager module (and may differ between managers).  The rest of the
  489.  * code only refers to virtual images by these pointer types, and never
  490.  * dereferences the pointer.
  491.  */
  492.  
  493. typedef struct big_sarray_control * big_sarray_ptr;
  494. typedef struct big_barray_control * big_barray_ptr;
  495.  
  496. /* Although a real ANSI C compiler can deal perfectly well with pointers to
  497.  * unspecified structures (see "incomplete types" in the spec), a few pre-ANSI
  498.  * and pseudo-ANSI compilers get confused.  To keep one of these bozos happy,
  499.  * add -DINCOMPLETE_TYPES_BROKEN to CFLAGS in your Makefile.  Then we will
  500.  * pseudo-define the structs as containing a single "dummy" field.
  501.  * The memory managers #define AM_MEMORY_MANAGER before including this file,
  502.  * so that they can make their own definitions of the structs.
  503.  */
  504.  
  505. #ifdef INCOMPLETE_TYPES_BROKEN
  506. #ifndef AM_MEMORY_MANAGER
  507. struct big_sarray_control { long dummy; };
  508. struct big_barray_control { long dummy; };
  509. #endif
  510. #endif
  511.  
  512.  
  513. /* Method types that need typedefs */
  514.  
  515. typedef METHOD(void, MCU_output_method_ptr, (compress_info_ptr cinfo,
  516.                          JBLOCK *MCU_data));
  517. typedef METHOD(void, MCU_output_caller_ptr, (compress_info_ptr cinfo,
  518.                          MCU_output_method_ptr output_method));
  519. typedef METHOD(void, downsample_ptr, (compress_info_ptr cinfo,
  520.                       int which_component,
  521.                       long input_cols, int input_rows,
  522.                       long output_cols, int output_rows,
  523.                       JSAMPARRAY above,
  524.                       JSAMPARRAY input_data,
  525.                       JSAMPARRAY below,
  526.                       JSAMPARRAY output_data));
  527. typedef METHOD(void, upsample_ptr, (decompress_info_ptr cinfo,
  528.                     int which_component,
  529.                     long input_cols, int input_rows,
  530.                     long output_cols, int output_rows,
  531.                     JSAMPARRAY above,
  532.                     JSAMPARRAY input_data,
  533.                     JSAMPARRAY below,
  534.                     JSAMPARRAY output_data));
  535. typedef METHOD(void, quantize_method_ptr, (decompress_info_ptr cinfo,
  536.                        int num_rows,
  537.                        JSAMPIMAGE input_data,
  538.                        JSAMPARRAY output_workspace));
  539. typedef METHOD(void, quantize_caller_ptr, (decompress_info_ptr cinfo,
  540.                        quantize_method_ptr quantize_method));
  541.  
  542.  
  543. /* These structs contain function pointers for the various JPEG methods. */
  544.  
  545. /* Routines to be provided by the surrounding application, rather than the
  546.  * portable JPEG code proper.  These are the same for compression and
  547.  * decompression.
  548.  */
  549.  
  550. struct External_methods_struct {
  551.     /* User interface: error exit and trace message routines */
  552.     /* NOTE: the string msgtext parameters will eventually be replaced
  553.      * by an enumerated-type code so that non-English error messages
  554.      * can be substituted easily.  This will not be done until all the
  555.      * code is in place, so that we know what messages are needed.
  556.      */
  557.     METHOD(void, error_exit, (const char *msgtext));
  558.     METHOD(void, trace_message, (const char *msgtext));
  559.  
  560.     /* Working data for error/trace facility */
  561.     /* See macros below for the usage of these variables */
  562.     int trace_level;    /* level of detail of tracing messages */
  563.     /* Use level 0 for important warning messages (nonfatal errors) */
  564.     /* Use levels 1, 2, 3 for successively more detailed trace options */
  565.  
  566.     /* For recoverable corrupt-data errors, we emit a warning message and
  567.      * keep going.  A surrounding application can check for bad data by
  568.      * seeing if num_warnings is nonzero at the end of processing.
  569.      */
  570.     long num_warnings;    /* number of corrupt-data warnings */
  571.     int first_warning_level; /* trace level for first warning */
  572.     int more_warning_level;    /* trace level for subsequent warnings */
  573.  
  574.     int message_parm[8];    /* store numeric parms for messages here */
  575.  
  576.     /* Memory management */
  577.     /* NB: alloc routines never return NULL. They exit to */
  578.     /* error_exit if not successful. */
  579.     METHOD(void *, alloc_small, (size_t sizeofobject));
  580.     METHOD(void, free_small, (void *ptr));
  581.     METHOD(void FAR *, alloc_medium, (size_t sizeofobject));
  582.     METHOD(void, free_medium, (void FAR *ptr));
  583.     METHOD(JSAMPARRAY, alloc_small_sarray, (long samplesperrow,
  584.                         long numrows));
  585.     METHOD(void, free_small_sarray, (JSAMPARRAY ptr));
  586.     METHOD(JBLOCKARRAY, alloc_small_barray, (long blocksperrow,
  587.                          long numrows));
  588.     METHOD(void, free_small_barray, (JBLOCKARRAY ptr));
  589.     METHOD(big_sarray_ptr, request_big_sarray, (long samplesperrow,
  590.                             long numrows,
  591.                             long unitheight));
  592.     METHOD(big_barray_ptr, request_big_barray, (long blocksperrow,
  593.                             long numrows,
  594.                             long unitheight));
  595.     METHOD(void, alloc_big_arrays, (long extra_small_samples,
  596.                     long extra_small_blocks,
  597.                     long extra_medium_space));
  598.     METHOD(JSAMPARRAY, access_big_sarray, (big_sarray_ptr ptr,
  599.                            long start_row,
  600.                            boolean writable));
  601.     METHOD(JBLOCKARRAY, access_big_barray, (big_barray_ptr ptr,
  602.                         long start_row,
  603.                         boolean writable));
  604.     METHOD(void, free_big_sarray, (big_sarray_ptr ptr));
  605.     METHOD(void, free_big_barray, (big_barray_ptr ptr));
  606.     METHOD(void, free_all, (void));
  607.  
  608.     long max_memory_to_use;    /* maximum amount of memory to use */
  609. };
  610.  
  611. /* Macros to simplify using the error and trace message stuff */
  612. /* The first parameter is generally cinfo->emethods */
  613.  
  614. /* Fatal errors (print message and exit) */
  615. #define ERREXIT(emeth,msg)        ((*(emeth)->error_exit) (msg))
  616. #define ERREXIT1(emeth,msg,p1)        ((emeth)->message_parm[0] = (p1), \
  617.                      (*(emeth)->error_exit) (msg))
  618. #define ERREXIT2(emeth,msg,p1,p2)    ((emeth)->message_parm[0] = (p1), \
  619.                      (emeth)->message_parm[1] = (p2), \
  620.                      (*(emeth)->error_exit) (msg))
  621. #define ERREXIT3(emeth,msg,p1,p2,p3)    ((emeth)->message_parm[0] = (p1), \
  622.                      (emeth)->message_parm[1] = (p2), \
  623.                      (emeth)->message_parm[2] = (p3), \
  624.                      (*(emeth)->error_exit) (msg))
  625. #define ERREXIT4(emeth,msg,p1,p2,p3,p4) ((emeth)->message_parm[0] = (p1), \
  626.                      (emeth)->message_parm[1] = (p2), \
  627.                      (emeth)->message_parm[2] = (p3), \
  628.                      (emeth)->message_parm[3] = (p4), \
  629.                      (*(emeth)->error_exit) (msg))
  630.  
  631. #define MAKESTMT(stuff)        do { stuff } while (0)
  632.  
  633. /* Nonfatal errors (we'll keep going, but the data is probably corrupt) */
  634. /* Note that warning count is incremented as a side-effect! */
  635. #define WARNMS(emeth,msg)    \
  636.   MAKESTMT( if ((emeth)->trace_level >= ((emeth)->num_warnings++ ? \
  637.         (emeth)->more_warning_level : (emeth)->first_warning_level)){ \
  638.         (*(emeth)->trace_message) (msg); } )
  639. #define WARNMS1(emeth,msg,p1)    \
  640.   MAKESTMT( if ((emeth)->trace_level >= ((emeth)->num_warnings++ ? \
  641.         (emeth)->more_warning_level : (emeth)->first_warning_level)){ \
  642.         (emeth)->message_parm[0] = (p1); \
  643.         (*(emeth)->trace_message) (msg); } )
  644. #define WARNMS2(emeth,msg,p1,p2)    \
  645.   MAKESTMT( if ((emeth)->trace_level >= ((emeth)->num_warnings++ ? \
  646.         (emeth)->more_warning_level : (emeth)->first_warning_level)){ \
  647.         (emeth)->message_parm[0] = (p1); \
  648.         (emeth)->message_parm[1] = (p2); \
  649.         (*(emeth)->trace_message) (msg); } )
  650.  
  651. /* Informational/debugging messages */
  652. #define TRACEMS(emeth,lvl,msg)    \
  653.   MAKESTMT( if ((emeth)->trace_level >= (lvl)) { \
  654.         (*(emeth)->trace_message) (msg); } )
  655. #define TRACEMS1(emeth,lvl,msg,p1)    \
  656.   MAKESTMT( if ((emeth)->trace_level >= (lvl)) { \
  657.         (emeth)->message_parm[0] = (p1); \
  658.         (*(emeth)->trace_message) (msg); } )
  659. #define TRACEMS2(emeth,lvl,msg,p1,p2)    \
  660.   MAKESTMT( if ((emeth)->trace_level >= (lvl)) { \
  661.         (emeth)->message_parm[0] = (p1); \
  662.         (emeth)->message_parm[1] = (p2); \
  663.         (*(emeth)->trace_message) (msg); } )
  664. #define TRACEMS3(emeth,lvl,msg,p1,p2,p3)    \
  665.   MAKESTMT( if ((emeth)->trace_level >= (lvl)) { \
  666.         int * _mp = (emeth)->message_parm; \
  667.         *_mp++ = (p1); *_mp++ = (p2); *_mp = (p3); \
  668.         (*(emeth)->trace_message) (msg); } )
  669. #define TRACEMS4(emeth,lvl,msg,p1,p2,p3,p4)    \
  670.   MAKESTMT( if ((emeth)->trace_level >= (lvl)) { \
  671.         int * _mp = (emeth)->message_parm; \
  672.         *_mp++ = (p1); *_mp++ = (p2); *_mp++ = (p3); *_mp = (p4); \
  673.         (*(emeth)->trace_message) (msg); } )
  674. #define TRACEMS8(emeth,lvl,msg,p1,p2,p3,p4,p5,p6,p7,p8)    \
  675.   MAKESTMT( if ((emeth)->trace_level >= (lvl)) { \
  676.         int * _mp = (emeth)->message_parm; \
  677.         *_mp++ = (p1); *_mp++ = (p2); *_mp++ = (p3); *_mp++ = (p4); \
  678.         *_mp++ = (p5); *_mp++ = (p6); *_mp++ = (p7); *_mp = (p8); \
  679.         (*(emeth)->trace_message) (msg); } )
  680.  
  681.  
  682. /* Methods used during JPEG compression. */
  683.  
  684. struct Compress_methods_struct {
  685.     /* Hook for user interface to get control after input_init */
  686.     METHOD(void, c_ui_method_selection, (compress_info_ptr cinfo));
  687.     /* Hook for user interface to do progress monitoring */
  688.     METHOD(void, progress_monitor, (compress_info_ptr cinfo,
  689.                     long loopcounter, long looplimit));
  690.     /* Input image reading & conversion to standard form */
  691.     METHOD(void, input_init, (compress_info_ptr cinfo));
  692.     METHOD(void, get_input_row, (compress_info_ptr cinfo,
  693.                      JSAMPARRAY pixel_row));
  694.     METHOD(void, input_term, (compress_info_ptr cinfo));
  695.     /* Color space and gamma conversion */
  696.     METHOD(void, colorin_init, (compress_info_ptr cinfo));
  697.     METHOD(void, get_sample_rows, (compress_info_ptr cinfo,
  698.                        int rows_to_read,
  699.                        JSAMPIMAGE image_data));
  700.     METHOD(void, colorin_term, (compress_info_ptr cinfo));
  701.     /* Expand picture data at edges */
  702.     METHOD(void, edge_expand, (compress_info_ptr cinfo,
  703.                    long input_cols, int input_rows,
  704.                    long output_cols, int output_rows,
  705.                    JSAMPIMAGE image_data));
  706.     /* Downsample pixel values of a single component */
  707.     /* There can be a different downsample method for each component */
  708.     METHOD(void, downsample_init, (compress_info_ptr cinfo));
  709.     downsample_ptr downsample[MAX_COMPS_IN_SCAN];
  710.     METHOD(void, downsample_term, (compress_info_ptr cinfo));
  711.     /* Extract samples in MCU order, process & hand off to output_method */
  712.     /* The input is always exactly N MCU rows worth of data */
  713.     METHOD(void, extract_init, (compress_info_ptr cinfo));
  714.     METHOD(void, extract_MCUs, (compress_info_ptr cinfo,
  715.                     JSAMPIMAGE image_data,
  716.                     int num_mcu_rows,
  717.                     MCU_output_method_ptr output_method));
  718.     METHOD(void, extract_term, (compress_info_ptr cinfo));
  719.     /* Entropy encoding parameter optimization */
  720.     METHOD(void, entropy_optimize, (compress_info_ptr cinfo,
  721.                     MCU_output_caller_ptr source_method));
  722.     /* Entropy encoding */
  723.     METHOD(void, entropy_encode_init, (compress_info_ptr cinfo));
  724.     METHOD(void, entropy_encode, (compress_info_ptr cinfo,
  725.                       JBLOCK *MCU_data));
  726.     METHOD(void, entropy_encode_term, (compress_info_ptr cinfo));
  727.     /* JPEG file header construction */
  728.     METHOD(void, write_file_header, (compress_info_ptr cinfo));
  729.     METHOD(void, write_scan_header, (compress_info_ptr cinfo));
  730.     METHOD(void, write_jpeg_data, (compress_info_ptr cinfo,
  731.                        char *dataptr,
  732.                        int datacount));
  733.     METHOD(void, write_scan_trailer, (compress_info_ptr cinfo));
  734.     METHOD(void, write_file_trailer, (compress_info_ptr cinfo));
  735.     /* Pipeline control */
  736.     METHOD(void, c_pipeline_controller, (compress_info_ptr cinfo));
  737.     METHOD(void, entropy_output, (compress_info_ptr cinfo,
  738.                       char *dataptr,
  739.                       int datacount));
  740.     /* Overall control */
  741.     METHOD(void, c_per_scan_method_selection, (compress_info_ptr cinfo));
  742. };
  743.  
  744. /* Methods used during JPEG decompression. */
  745.  
  746. struct Decompress_methods_struct {
  747.     /* Input image reading & conversion to standard form */
  748.     METHOD(void, input_init, (decompress_info_ptr cinfo));
  749.     METHOD(void, get_input_row, (decompress_info_ptr cinfo,
  750.                      JSAMPARRAY pixel_row));
  751.     METHOD(void, input_term, (decompress_info_ptr cinfo));
  752.     /* Hook for user interface to get control after reading file header */
  753.     METHOD(void, d_ui_method_selection, (decompress_info_ptr cinfo));
  754.     /* Hook for user interface to do progress monitoring */
  755.     METHOD(void, progress_monitor, (decompress_info_ptr cinfo,
  756.                     long loopcounter, long looplimit));
  757.     /* JPEG file scanning */
  758.     METHOD(void, read_file_header, (decompress_info_ptr cinfo));
  759.     METHOD(boolean, read_scan_header, (decompress_info_ptr cinfo));
  760.     METHOD(int, read_jpeg_data, (decompress_info_ptr cinfo));
  761.     METHOD(void, resync_to_restart, (decompress_info_ptr cinfo,
  762.                      int marker));
  763.     METHOD(void, read_scan_trailer, (decompress_info_ptr cinfo));
  764.     METHOD(void, read_file_trailer, (decompress_info_ptr cinfo));
  765.     /* Entropy decoding */
  766.     METHOD(void, entropy_decode_init, (decompress_info_ptr cinfo));
  767.     METHOD(void, entropy_decode, (decompress_info_ptr cinfo,
  768.                       JBLOCKROW *MCU_data));
  769.     METHOD(void, entropy_decode_term, (decompress_info_ptr cinfo));
  770.     /* MCU disassembly: fetch MCUs from entropy_decode, build coef array */
  771.     /* The reverse_DCT step is in the same module for symmetry reasons */
  772.     METHOD(void, disassemble_init, (decompress_info_ptr cinfo));
  773.     METHOD(void, disassemble_MCU, (decompress_info_ptr cinfo,
  774.                        JBLOCKIMAGE image_data));
  775.     METHOD(void, reverse_DCT, (decompress_info_ptr cinfo,
  776.                    JBLOCKIMAGE coeff_data,
  777.                    JSAMPIMAGE output_data, int start_row));
  778.     METHOD(void, disassemble_term, (decompress_info_ptr cinfo));
  779.     /* Cross-block smoothing */
  780.     METHOD(void, smooth_coefficients, (decompress_info_ptr cinfo,
  781.                        jpeg_component_info *compptr,
  782.                        JBLOCKROW above,
  783.                        JBLOCKROW currow,
  784.                        JBLOCKROW below,
  785.                        JBLOCKROW output));
  786.     /* Upsample pixel values of a single component */
  787.     /* There can be a different upsample method for each component */
  788.     METHOD(void, upsample_init, (decompress_info_ptr cinfo));
  789.     upsample_ptr upsample[MAX_COMPS_IN_SCAN];
  790.     METHOD(void, upsample_term, (decompress_info_ptr cinfo));
  791.     /* Color space and gamma conversion */
  792.     METHOD(void, colorout_init, (decompress_info_ptr cinfo));
  793.     METHOD(void, color_convert, (decompress_info_ptr cinfo,
  794.                      int num_rows, long num_cols,
  795.                      JSAMPIMAGE input_data,
  796.                      JSAMPIMAGE output_data));
  797.     METHOD(void, colorout_term, (decompress_info_ptr cinfo));
  798.     /* Color quantization */
  799.     METHOD(void, color_quant_init, (decompress_info_ptr cinfo));
  800.     METHOD(void, color_quantize, (decompress_info_ptr cinfo,
  801.                       int num_rows,
  802.                       JSAMPIMAGE input_data,
  803.                       JSAMPARRAY output_data));
  804.     METHOD(void, color_quant_prescan, (decompress_info_ptr cinfo,
  805.                        int num_rows,
  806.                        JSAMPIMAGE image_data,
  807.                        JSAMPARRAY workspace));
  808.     METHOD(void, color_quant_doit, (decompress_info_ptr cinfo,
  809.                     quantize_caller_ptr source_method));
  810.     METHOD(void, color_quant_term, (decompress_info_ptr cinfo));
  811.     /* Output image writing */
  812.     METHOD(void, output_init, (decompress_info_ptr cinfo));
  813.     METHOD(void, put_color_map, (decompress_info_ptr cinfo,
  814.                      int num_colors, JSAMPARRAY colormap));
  815.     METHOD(void, put_pixel_rows, (decompress_info_ptr cinfo,
  816.                       int num_rows,
  817.                       JSAMPIMAGE pixel_data));
  818.     METHOD(void, output_term, (decompress_info_ptr cinfo));
  819.     /* Pipeline control */
  820.     METHOD(void, d_pipeline_controller, (decompress_info_ptr cinfo));
  821.     /* Overall control */
  822.     METHOD(void, d_per_scan_method_selection, (decompress_info_ptr cinfo));
  823. };
  824.  
  825.  
  826. /* External declarations for routines that aren't called via method ptrs. */
  827. /* Note: use "j" as first char of names to minimize namespace pollution. */
  828. /* The PP macro hides prototype parameters from compilers that can't cope. */
  829.  
  830. #ifdef PROTO
  831. #define PP(arglist)    arglist
  832. #else
  833. #define PP(arglist)    ()
  834. #endif
  835.  
  836.  
  837. /* main entry for compression */
  838. EXTERN void jpeg_compress PP((compress_info_ptr cinfo));
  839.  
  840. /* default parameter setup for compression */
  841. EXTERN void j_c_defaults PP((compress_info_ptr cinfo, int quality,
  842.                  boolean force_baseline));
  843. EXTERN void j_monochrome_default PP((compress_info_ptr cinfo));
  844. EXTERN void j_set_quality PP((compress_info_ptr cinfo, int quality,
  845.                   boolean force_baseline));
  846. /* advanced compression parameter setup aids */
  847. EXTERN void j_add_quant_table PP((compress_info_ptr cinfo, int which_tbl,
  848.                   const QUANT_VAL *basic_table,
  849.                   int scale_factor, boolean force_baseline));
  850. EXTERN int j_quality_scaling PP((int quality));
  851.  
  852. /* main entry for decompression */
  853. EXTERN void jpeg_decompress PP((decompress_info_ptr cinfo));
  854.  
  855. /* default parameter setup for decompression */
  856. EXTERN void j_d_defaults PP((decompress_info_ptr cinfo,
  857.                  boolean standard_buffering));
  858.  
  859. /* forward DCT */
  860. EXTERN void j_fwd_dct PP((DCTBLOCK data));
  861. /* inverse DCT */
  862. EXTERN void j_rev_dct PP((DCTBLOCK data));
  863.  
  864. /* utility routines in jutils.c */
  865. EXTERN long jround_up PP((long a, long b));
  866. EXTERN void jcopy_sample_rows PP((JSAMPARRAY input_array, int source_row,
  867.                   JSAMPARRAY output_array, int dest_row,
  868.                   int num_rows, long num_cols));
  869. EXTERN void jcopy_block_row PP((JBLOCKROW input_row, JBLOCKROW output_row,
  870.                 long num_blocks));
  871. EXTERN void jzero_far PP((void FAR * target, size_t bytestozero));
  872.  
  873. /* method selection routines for compression modules */
  874. EXTERN void jselcpipeline PP((compress_info_ptr cinfo)); /* jcpipe.c */
  875. EXTERN void jselchuffman PP((compress_info_ptr cinfo)); /* jchuff.c */
  876. EXTERN void jselcarithmetic PP((compress_info_ptr cinfo)); /* jcarith.c */
  877. EXTERN void jselexpand PP((compress_info_ptr cinfo)); /* jcexpand.c */
  878. EXTERN void jseldownsample PP((compress_info_ptr cinfo)); /* jcsample.c */
  879. EXTERN void jselcmcu PP((compress_info_ptr cinfo)); /* jcmcu.c */
  880. EXTERN void jselccolor PP((compress_info_ptr cinfo));    /* jccolor.c */
  881. /* The user interface should call one of these to select input format: */
  882. EXTERN void jselrgif PP((decompress_info_ptr cinfo)); /* jrdgif.c */
  883. EXTERN void jselrppm PP((decompress_info_ptr cinfo)); /* jrdppm.c */
  884. EXTERN void jselrrle PP((decompress_info_ptr cinfo)); /* jrdrle.c */
  885. EXTERN void jselrtarga PP((decompress_info_ptr cinfo)); /* jrdtarga.c */
  886. /* and one of these to select output header format: */
  887. EXTERN void jselwjfif PP((compress_info_ptr cinfo)); /* jwrjfif.c */
  888.  
  889. /* method selection routines for decompression modules */
  890. EXTERN void jseldpipeline PP((decompress_info_ptr cinfo)); /* jdpipe.c */
  891. EXTERN void jseldhuffman PP((decompress_info_ptr cinfo)); /* jdhuff.c */
  892. EXTERN void jseldarithmetic PP((decompress_info_ptr cinfo)); /* jdarith.c */
  893. EXTERN void jseldmcu PP((decompress_info_ptr cinfo)); /* jdmcu.c */
  894. EXTERN void jselbsmooth PP((decompress_info_ptr cinfo)); /* jbsmooth.c */
  895. EXTERN void jselupsample PP((decompress_info_ptr cinfo)); /* jdsample.c */
  896. EXTERN void jseldcolor PP((decompress_info_ptr cinfo));    /* jdcolor.c */
  897. EXTERN void jsel1quantize PP((decompress_info_ptr cinfo)); /* jquant1.c */
  898. EXTERN void jsel2quantize PP((decompress_info_ptr cinfo)); /* jquant2.c */
  899. /* The user interface should call one of these to select input format: */
  900. EXTERN void jselrjfif PP((decompress_info_ptr cinfo)); /* jrdjfif.c */
  901. /* and one of these to select output image format: */
  902. EXTERN void jselwgif PP((decompress_info_ptr cinfo)); /* jwrgif.c */
  903. EXTERN void jselwppm PP((decompress_info_ptr cinfo)); /* jwrppm.c */
  904. EXTERN void jselwmem PP((decompress_info_ptr cinfo)); /* jwrmem.c */
  905. EXTERN void jselwrle PP((decompress_info_ptr cinfo)); /* jwrrle.c */
  906. EXTERN void jselwtarga PP((decompress_info_ptr cinfo)); /* jwrtarga.c */
  907.  
  908. /* method selection routines for system-dependent modules */
  909. EXTERN void jselerror PP((external_methods_ptr emethods)); /* jerror.c */
  910. EXTERN void jselmemmgr PP((external_methods_ptr emethods)); /* jmemmgr.c */
  911.  
  912.  
  913. extern decompress_info_ptr LoadJPEG(char *filename,UWORD colors,UBYTE *r,UBYTE *g,UBYTE *b,UBYTE **p);
  914.  
  915. /* We assume that right shift corresponds to signed division by 2 with
  916.  * rounding towards minus infinity.  This is correct for typical "arithmetic
  917.  * shift" instructions that shift in copies of the sign bit.  But some
  918.  * C compilers implement >> with an unsigned shift.  For these machines you
  919.  * must define RIGHT_SHIFT_IS_UNSIGNED.
  920.  * RIGHT_SHIFT provides a proper signed right shift of an INT32 quantity.
  921.  * It is only applied with constant shift counts.  SHIFT_TEMPS must be
  922.  * included in the variables of any routine using RIGHT_SHIFT.
  923.  */
  924.  
  925. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  926. #define SHIFT_TEMPS    INT32 shift_temp;
  927. #define RIGHT_SHIFT(x,shft)  \
  928.     ((shift_temp = (x)) < 0 ? \
  929.      (shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \
  930.      (shift_temp >> (shft)))
  931. #else
  932. #define SHIFT_TEMPS
  933. #define RIGHT_SHIFT(x,shft)    ((x) >> (shft))
  934. #endif
  935.  
  936.  
  937. /* Miscellaneous useful macros */
  938.  
  939. #undef MAX
  940. #define MAX(a,b)    ((a) > (b) ? (a) : (b))
  941. #undef MIN
  942. #define MIN(a,b)    ((a) < (b) ? (a) : (b))
  943.  
  944.  
  945. #define RST0    0xD0        /* RST0 marker code */
  946.